package cn.itcast.nio.c1;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class TestFileCopy {
    public static void main(String[] args) throws IOException {
        String source = "D:\\openjdk\\jdk12-06222165c35f";
        String target = "D:\\openjdk\\jdk12-06222165c35faBc";

        Files.walk(Paths.get(source)).forEach((path -> {
            String targetPath = path.toString().replace(source,target);
            // 判断是否是目录
            if(Files.isDirectory(path)){
                try {
                    Files.createDirectory(Paths.get(targetPath));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }else if(Files.isRegularFile(path)){
                try {
                    Files.copy(path,Paths.get(targetPath));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }));
    }
}
